<?php

class Customers extends Eloquent {
    protected $table = 'customers';
     public static function Select($shop_id)
    {
        try{

            $query_select="SELECT *  FROM customers where shop_id = $shop_id ";
            return DB::select(DB::raw($query_select));
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function Insert($name,$address,$phone,$email,$comments,$gender,$shop_id)
    {
      try{

            $customer= new Customers();
            $customer->name = $name;
            $customer->address =$address;
            $customer->phone=$phone;
            $customer->email=$email;
            $customer->comments=$comments;
            $customer->gender=$gender;
            $customer->shop_id = $shop_id;

            $customer->save();
            $customer_id = $customer->id;
            return $customer_id;
          }
        catch(Exception $e)
        {
            throw $e;
        }
    }

    
    
    public static function Edit($name,$address,$phone,$email,$comments,$customer_id)
    {

        try{

            $query_edit =" UPDATE customers 
                           SET updated_at=CURRENT_TIMESTAMP,name = '$name',address = '$address', phone=$phone,email = '$email', comments='$comments'
                           WHERE id = $customer_id";
            $query= DB::update($query_edit);
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    
    
       public static function Del($customer_id){
        try{
            $query_delete ="DELETE FROM customers WHERE id = '$customer_id'";
            $delete=DB::delete($query_delete);
            return true;
        }
        catch(Exception $e){
            throw $e;
        }
    }

}
